#!/bin/sh
#filename: wan_4g_load.sh

WAN_4G_IF='3g-4G'
WAN_SAT_IF='br-lan'

WAN_4G_INET=`ifconfig ${WAN_4G_IF} | grep inet | cut -d ' ' -f12 | cut -d ':' -f2`
WAN_4G_PTP=`ifconfig ${WAN_4G_IF} | grep P-t-P | cut -d ' ' -f14 | cut -d ':' -f2`
WAN_SAT_INET=`ifconfig ${WAN_SAT_IF} | grep inet | cut -d ' ' -f12 | cut -d ':' -f2`

dev_mode=`cat /etc/config/devmode | grep option | grep mode | awk -F "\'" '{print $2}'`

if [ "${dev_mode}" != "nac" ]; then
	exit 1
fi

if [ -z "${WAN_4G_INET}" -o -z "${WAN_4G_PTP}" -o -z "${WAN_SAT_INET}" ]; then
	exit 1
fi

if [ "${WAN_SAT_INET}" = "0.0.0.0" -o "${WAN_SAT_INET}" = "192.168.1.1" -o "${WAN_SAT_INET}" = "192.168.222.5" ]; then
	exit 1
fi

WAN_SAT_IPS24=${WAN_SAT_INET%.*}
WAN_SAT_IPL8=${WAN_SAT_INET##*.}

if [ "${WAN_SAT_IPS24}" = "0.0.0" -o "${WAN_SAT_IPS24}" = "192.168.1" -o "${WAN_SAT_IPS24}" = "192.168.222" ]; then
	exit 1
fi

if [ "${WAN_SAT_IPL8}" != "180" ]; then
	exit 1
fi

######################

WAN_SAT_GW=${WAN_SAT_IPS24}.1

ip route del 192.168.16.0/24 &> /dev/null
ip route add 192.168.16.0/24 via ${WAN_SAT_GW} &> /dev/null

ip route del 172.20.0.50/32 &> /dev/null
ip route add 172.20.0.50/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 172.30.0.101/32 &> /dev/null
ip route add 172.30.0.101/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 172.30.0.103/32 &> /dev/null
ip route add 172.30.0.103/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 10.0.0.195/32 &> /dev/null
ip route add 10.0.0.195/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 10.0.0.217/32 &> /dev/null
ip route add 10.0.0.217/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 10.0.0.218/32 &> /dev/null
ip route add 10.0.0.218/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 10.0.0.219/32 &> /dev/null
ip route add 10.0.0.219/32 via ${WAN_SAT_GW} &> /dev/null

ip route del 10.0.0.231/32 &> /dev/null
ip route add 10.0.0.231/32 via ${WAN_SAT_GW} &> /dev/null

######################

exit 0

